/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.p10.miage.gestionabsence.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Sofian Seid
 */
public class IntervenantBDD {

    public IntervenantBDD() {
    }
    
    public static Intervenant trouverParLoginEtPassword(String login, String password) throws SQLException, Exception {
        Intervenant intervenant = new Intervenant();
        String sql="SELECT * FROM INTERVENANT WHERE MAIL = ?";
        PreparedStatement pst = Connection.getBDD().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        pst.setString(1, login);
        if (pst.execute()) {
            ResultSet resultat = pst.getResultSet();
            if(resultat.first()==true) {
                if(password.equals(resultat.getString("PASSWD"))) {
                    intervenant.init(resultat);
                } else {
                    throw new Exception("Mot de passe incorrect");
                }
            }
            else{
                throw new Exception("Login incorrect");
            }
            resultat.close();
        }
        return intervenant;
    }
}
